package org.sanguine.study.hometasks.first.task.a;

import org.sanguine.study.hometasks.first.Runner;

public class TaskA1 extends CommonStringTask {
	private String shortestString = "";
	private String longestString = "";

	public static void main(String[] args) {
		Runner runner = new TaskA1();
		runner.run(args);
	}
	
	@Override
	public void doTask() {
		if (in == null || out == null || numberOfItems <= 0) return;
		readItems();
		if (items != null) findStrings();
		printCurrentResult();
	}

	private void printCurrentResult() {
		out.printf("%d: '%s'\n", shortestString.length(), shortestString);
		out.printf("%d: '%s'\n", longestString.length(), longestString);
	}

	private void findStrings() {
		if (items.length == 0) return;

		int minLength = 0;
		int maxLength = 0;

		shortestString = longestString = items[0];
		maxLength = minLength = items[0].length();

		for (String s : items) {
			if (s.length() < minLength) {
				minLength = s.length(); 
				shortestString = s;
			} else if (s.length() > maxLength) {
				maxLength = s.length(); 
				longestString = s;
			}
		}
	}
}
